package monster.com.cvh.activity;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.KeyEvent;

import monster.com.cvh.R;
import monster.com.cvh.activity.base.PermissionActivity;
import monster.com.cvh.constant.Constans;
import monster.com.cvh.fragment.EducationFragment;
import monster.com.cvh.fragment.ExperienceInSchoolFragment;
import monster.com.cvh.fragment.HonorCertificateFragment;
import monster.com.cvh.fragment.OccupationIntentFragment;
import monster.com.cvh.fragment.PersonalInfoFragment;
import monster.com.cvh.fragment.ProfessionalSkillFragment;
import monster.com.cvh.fragment.ProjectExperienceFragment;
import monster.com.cvh.fragment.QualificationFragment;
import monster.com.cvh.fragment.SelfEvaluationFragment;
import monster.com.cvh.fragment.WorkExperienceFragment;
import monster.com.cvh.fragment.base.ResumeInfoBaseFragment;

/**
 * @author: 13580
 * @data: 2018/3/19
 * @function:编辑个人各项信息Activity
 */
public class UserMessagerEdtActivity extends PermissionActivity {

    private static final String TAG = "UserMessagerEdtActivity";
    private ResumeInfoBaseFragment mFragment;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_user_messager_edt;
    }

    @Override
    protected void initEvent() {
        changeStatusBarColorDark(this, R.color.white);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            int code = intent.getIntExtra(Constans.USER_MSG_EDT, -1);
            switch (code) {
                case Constans.PERSONAL_INFO:
                    showFragment(PersonalInfoFragment.newInstance());
                    break;
                case Constans.OCCUPATION_INTENT:
                    showFragment(OccupationIntentFragment.newInstance());
                    break;
                case Constans.EDUCATION:
                    showFragment(EducationFragment.newInstance());
                    break;
                case Constans.HONOR_CERTIFICATE:
                    showFragment(HonorCertificateFragment.newInstance());
                    break;
                case Constans.EXPERIENCE_IN_SCHOOL:
                    showFragment(ExperienceInSchoolFragment.newInstance());
                    break;
                case Constans.WORK_EXPERIENCE:
                    showFragment(WorkExperienceFragment.newInstance());
                    break;
                case Constans.PROFESSIONAL_SKILL:
                    showFragment(ProfessionalSkillFragment.newInstance());
                    break;
                case Constans.QUALIFICATION:
                    showFragment(QualificationFragment.newInstance());
                    break;
                case Constans.PROJECT_EXPERIENCE:
                    showFragment(ProjectExperienceFragment.newInstance());
                    break;
                case Constans.SELF_EVALUATION:
                    showFragment(SelfEvaluationFragment.newInstance());
                    break;
            }
        }
    }

    private void showFragment(@NonNull Fragment fragment) {
        mFragment = (ResumeInfoBaseFragment) fragment;
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.cfl_activity_user_messager, fragment);
        transaction.commit();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.e(TAG, "按啦: ");
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && mFragment != null && !mFragment.isDataChanged()) {
            mFragment.onExit();
            Log.e(TAG, "调用啦: " + mFragment.isDataChanged());
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e(TAG, "游客回来啦: 请求码" + requestCode + ";结果码" + resultCode);
    }
}
